<template>
	<view>
		<ttBar leftIcon="icon-back" title="课程评价"></ttBar>
		<view class="eltList" v-if="eltList.length>0">
			<eltItemGood v-for="(item,index) in eltList" :key="index" :evaluateItem="item"></eltItemGood>
		</view>
		<emptyBox v-if="eltList.length<1"></emptyBox>
	</view>
</template>

<script>
	import eltItemGood from "@/components/evaluate/eltItemGood.vue";
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	export default {
		computed:{
			...mapState({
				userInfo:state=>state.user.userInfo,
				isLogin:state=>state.user.isLogin
			})
		},
		components:{
			eltItemGood
		},
		data() {
			return {
				eltList:[],
				page_no:1,
				hasNext:true,
				goodId:0,
				goodName:''
			};
		},
		methods:{
			getData(){
				if(this.hasNext){
					this.$store.dispatch("apiGetAllElt",{
						courseId:this.goodId,
						page_no:this.page_no,
						page_size:10

					})
					.then(res=>{
						this.eltList=this.eltList.concat(res.data.data.items)
						this.hasNext=res.data.data.hasNext;
						this.page_no=res.data.data.nextPage;
					})
				}else{
					uni.showToast({
						title: '没有更多的评论了',
						icon: 'none'
					});
				}
				
			}
		},
		onLoad(cfm) {
			this.goodId=cfm.gid;
			this.goodName=cfm.gname;
			this.getData()
		},
		// 下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.getData()
				uni.stopPullDownRefresh();
			}, 1500)
		},
		// 页面滚动到底部
		onReachBottom() {
			this.getData()
		},
	}
</script>

<style lang="less">
	page{
		background-color: #f3f3f3;
	}
	.eltList{
		padding: 18upx;
	}
</style>
